﻿using System;
using System.Windows.Forms;

namespace DinnerParty
{
    public partial class Form1 : Form
    {
        private DinnerParty _dinnerParty;

        public Form1()
        {
            InitializeComponent();

            _dinnerParty = new DinnerParty((int) NudPeople.Value, ChkFancy.Checked, ChkHealthy.Checked);

            DisplayDinnerPartyCost();
        }

        private void DisplayDinnerPartyCost()
        {
            LblCost.Text = _dinnerParty.Cost.ToString("C");
        }

        private void NudPeople_ValueChanged(object sender, EventArgs e)
        {
            _dinnerParty.NumberOfPeople = (int)NudPeople.Value;
            DisplayDinnerPartyCost();
        }

        private void ChkFancy_CheckedChanged(object sender, EventArgs e)
        {
            _dinnerParty.FancyDecorations = ChkFancy.Checked;
            DisplayDinnerPartyCost();
        }

        private void ChkHealthy_CheckedChanged(object sender, EventArgs e)
        {
            _dinnerParty.HealthyOption = ChkHealthy.Checked;
            DisplayDinnerPartyCost();
        }
    }


    public class DinnerParty
    {
        public const int CostOfFoodPerPerson = 25;

        public int NumberOfPeople { get; set; }

        public bool FancyDecorations { get; set; }

        public bool HealthyOption { get; set; }

        public decimal Cost
        {
            get
            {
                var totalCost = CalculateCostOfDecorations();
                totalCost += (CalculateCostOfBeveragesPerPerson() + CostOfFoodPerPerson) * NumberOfPeople;

                if (HealthyOption)
                {
                    totalCost *= 0.95M;
                }
                return totalCost;
            }
        }

        public DinnerParty(int numberOfPeople, bool fancyDecorations, bool healthyOption)
        {
            NumberOfPeople = numberOfPeople;
            FancyDecorations = fancyDecorations;
            HealthyOption = healthyOption;
        }

        private decimal CalculateCostOfDecorations()
        {
            if (FancyDecorations)
            {
                return NumberOfPeople * 15M + 50M;
            }
            else
            {
                return NumberOfPeople * 7.5M + 30M;
            }
        }

        private decimal CalculateCostOfBeveragesPerPerson()
        {
            if (HealthyOption)
            {
                return 5M;
            }
            else
            {
                return 20M;
            }
        }
    }
}
